package com.aim.analysis.records;

/**
 * User: Avraham Shvartzon
 * Date: 1/30/15
 */
public class DiscountPredictor implements PerformancePredictor<DiscountPredictor.Params> {

    Params p;

    @Override
    public double[] predict(double[] performance) {
        double currentPrediction = p.initialAverage;
        double[] prediction = new double[performance.length];
        for (int i = 0; i < performance.length; i++) {
            prediction[i] = currentPrediction;
            currentPrediction = currentPrediction * p.discountFactor + performance[i] * (1 - p.discountFactor);
        }
        return prediction;
    }

    @Override
    public void setParameters(Params parameters) {
        this.p = parameters;
    }

    public static class Params {
        final double initialAverage;
        final double discountFactor;

        public Params(double initialAverage, double discountFactor) {
            this.initialAverage = initialAverage;
            this.discountFactor = discountFactor;
        }

        @Override
        public String toString() {
            return "initialAverage=" + initialAverage +
                    "\tdiscountFactor=" + discountFactor;
        }
    }
}
